function [] = part7()
clc
clear


X = [03 16 21];
D = [53 09 45];
 
potens = [01 00 00 00 00];
 
b = 64;


% -- calculations

X_d = conv_to10(X,b);
D_d = conv_to10(D,b);
potens_d = conv_to10(potens,b);

X_d
D_d
potens_d

p_d = potens_d/D_d;
p_d

p_approx_d = round(p_d);
p_approx_d

%Xp_approx_d = X_d*p_approx_d;
%Dp_approx_d = D_d*p_approx_d;

%Xp_approx_d
%Dp_approx_d

%t_d = (Dp_approx_d/potens_d-1)*b^4;
%t_d

r0_d = X_d;

disp('===iter1');
% iter1
r1_d = r0_d*p_approx_d;
r1_d

r1 = [03 58 41 17];

z1 = r1(1);
z1_d = conv_to10(z1,b);
z1_d

z1D_d = z1_d*D_d;
z1D_d

r0_d = b*r0_d-z1D_d;
r0_d

r0 = [00 19 03 22];

disp('===iter2');
% iter2
r1_d = r0_d*p_approx_d;
r1_d

r1 = [58 51 15 37];

z1 = r1(1);
z1_d = conv_to10(z1,b);
z1_d

z1D_d = z1_d*D_d;
z1D_d

r0_d = b*r0_d-z1D_d;
r0_d

r0 = [00 19 03 22];

disp('===iter3');
%iter3
r1_d = r0_d*p_approx_d;
r1_d

r1 = [54 16 30 54];

z1 = r1(1);
z1_d = conv_to10(z1,b);
z1_d

z1D_d = z1_d*D_d;
z1D_d

b
r0_d
z1D_d

r0_d = b*r0_d-z1D_d;
r0_d

r0 = [00 19 03 22];



end

function d = conv_to10(B,b)
    len = length(B);
    d = sum(b.^(len-1:-1:0).*B);
end